package com.icloud.cer.rest.msg.bean;

import java.io.IOException;

import com.icloud.cer.rest.Constants;
import com.icloud.cer.rest.msg.AbsMsgObject;
import com.icloud.cer.rest.msg.BDataFilterInputStream;
import com.icloud.cer.rest.msg.DataFilterOutputStream;

public class EncryptRequest  extends AbsMsgObject<EncryptRequest>{
	public static final int BYTE_COUNT = 304;
	private String certification;//256
	private long sequence;//8
	private long taskId;//8
	private String userId;//32
	
	@Override
	protected void doSerialize(DataFilterOutputStream dos) throws IOException {
		dos.writeBytes(certification);
		dos.writeLong(sequence);
		dos.writeLong(taskId);
		dos.writeBytes(new String(userId.getBytes(),Constants.CHARSET));
		int remainderLen = 32 - userId.length();
		if(remainderLen > 0) {
			dos.writeBytes(new String(new byte[remainderLen],Constants.CHARSET));
		}
		
	}

	@Override
	protected EncryptRequest doDeserialize(BDataFilterInputStream dis) throws IOException {
		byte[] cer = new byte[256];
		byte[] user = new byte[32];
		dis.read(cer);
		sequence = dis.readLong();
		taskId = dis.readLong();
		dis.read(user);
		
		this.certification = new String(cer,Constants.CHARSET);
		this.userId = new String(user, Constants.CHARSET);
		return this;
	}

	public String getCertification() {
		return certification;
	}

	public void setCertification(String certification) {
		this.certification = certification;
	}

	public long getSequence() {
		return sequence;
	}

	public void setSequence(long sequence) {
		this.sequence = sequence;
	}

	public long getTaskId() {
		return taskId;
	}

	public void setTaskId(long taskId) {
		this.taskId = taskId;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}
	

}
